package com.shiyun.marker.cli.command;

import cn.hutool.core.bean.BeanUtil;
import com.shiyun.marker.generator.file.FileGenerator;
import com.shiyun.marker.model.DataModel;
import lombok.Data;
import picocli.CommandLine;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;

@CommandLine.Command(name="generator",mixinStandardHelpOptions = true)
@Data
public class GeneratorCommand implements Callable<Integer> {
    //定义命令行选项
    <#list modelConfig.models as meodelInfo>
        @Option(names={<#if modelInfo.abbr ??>"-${modelInfo.abbr}"</#if>,"--${modelInfo.fileName}"},arity = "0..1",description = "${modelInfo.description}" ,interactive = true,echo = true)
        private ${modelInfo.type} ${modelInfo.fileName} <#if modelInfo.defaultValue??>= "${modelInfo.defaultValue}"</#if>;
    </#list>


    @Override
    public Integer call() throws Exception {
        DataModel dataModel = new DataModel();
        BeanUtil.copyProperties(this, dataModel);
        System.out.println("配置信息"+ dataModel);
        //调用生成方法
        FileGenerator.doGenerator(dataModel);
        return 0;
    }
}
